package com.maimao.order.client.factory;

import com.maimao.core.model.resp.PageResult;
import com.maimao.core.model.resp.Result;
import com.maimao.model.goods.log.GoodsCheck;
import com.maimao.model.goods.log.GoodsCheckInput;
import com.maimao.model.order.es.EsOrder;
import com.maimao.model.order.input.OrderSearchInput;
import com.maimao.order.client.EsClient;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author MaoLin Wang
 * @date 2020/11/30 10:03 下午
 */
@Component
@Slf4j
public class EsFallBackFactory implements FallbackFactory<EsClient> {

    @Override
    public EsClient create(Throwable cause) {
        String errorMsg = cause.getMessage() == null ? "" : cause.getMessage();

        return new EsClient() {
            @Override
            public Result saveBatch(List<EsOrder> orderList) {
                log.error("调用[EsClient-saveBatch({})]出错 :{}", orderList, errorMsg);
                return Result.fail(errorMsg);
            }

            @Override
            public Result<PageResult<EsOrder>> list(OrderSearchInput input, Integer page, Integer size) {
                log.error("调用[EsClient-list({},{},{})]出错 :{}", input, page, size, errorMsg);
                return Result.fail(errorMsg);
            }


        };
    }
}
